import type { RowType } from '#/views/system/dict/dict.data';

import { requestClient } from '#/api/request';

export namespace SysDictTableApi {
  export type RowTypeFetchParams = RowType;
  export interface IdFetchParams {
    id: string;
  }
  export interface ListFetchParams {
    [key: string]: any;
  }
  export interface PageListFetchParams {
    [key: string]: any;
    pageNo: number;
    pageSize: number;
  }
  export interface CacheDictParams {
    dictCode: string;
  }
}

/**
 * 分页列表查询
 */
export async function dictQueryPageListApi(
  params: SysDictTableApi.PageListFetchParams,
) {
  return requestClient.get('/sys/dict/queryPageList', { params });
}

/**
 * 列表查询
 */
export async function dictQueryListApi(
  params: SysDictTableApi.ListFetchParams,
) {
  return requestClient.get('/sys/dict/queryList', { params });
}

/**
 * 通过ID查询
 * @param params
 */
export async function dictQueryByIdApi(params: SysDictTableApi.IdFetchParams) {
  return requestClient.get('/sys/dict/queryById', { params });
}

/**
 * 新增
 */
export async function dictAddApi(params: SysDictTableApi.RowTypeFetchParams) {
  return requestClient.post('/sys/dict/add', params);
}

/**
 * 编辑
 */
export async function dictEditApi(params: SysDictTableApi.RowTypeFetchParams) {
  return requestClient.post('/sys/dict/edit', params);
}

/**
 * 删除
 * @param id 主键
 */
export async function dictDelApi(id) {
  return requestClient.delete<boolean>(`/sys/dict/delete/${id}`);
}

/**
 * 批量删除删除
 * @param ids 主键
 */
export async function dictDeleteBatchApi(ids) {
  return requestClient.delete<boolean>(`/sys/dict/deleteBatchByIds/${ids}`);
}

/**
 * 刷新缓存
 */
export async function dictRefreshCacheApi() {
  return requestClient.get('/sys/dict/refreshCache');
}

/**
 * 根据字典code获取字典项
 */
export async function queryDictCacheApi(
  params: SysDictTableApi.CacheDictParams,
) {
  return requestClient.get('/sys/dict/queryDictCache', { params });
}
